﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static WinFormsApp1.Leo.ListWeeks03.SaleShow;
using WinFormsApp1.Common;

namespace WinFormsApp1.WangHaoQi._02Winfroms
{
    public partial class OilyfatShow : Form
    {
        public OilyfatShow()
        {
            InitializeComponent();
        }

        public class Oilyfats
        {
            public int pageIndex { get; set; }

            public int pageSize { get; set; }
        };


        public int pageIndex = 1;

        public int pageSize = 3;

        public int totalcount = 0;

        public int pagecount = 0;

        private async void OilyfatShow_Load(object sender, EventArgs e)
        {
            var clients = new Saleres
            {
                pageIndex = pageIndex,
                pageSize = pageSize,
            };

            var items = await HttpClientHelper.RequestUrl<object, ApiResultFY1<List<Oilyfatse>>>(URLCommon.Url2, "/WeekListOne_Leo/GeOilyfatShow", HttpClientHelper.MethodType.POST, clients);
            this.dataGridView1.DataSource = items.Data.list;
            totalcount = items.Data.totalcount;
            pagecount = items.Data.pagecount;

            label1.Text = "共" + totalcount + "条,每页" + pageSize + "条，当前第" + pageIndex + "页，共" + pagecount + "页";
        }

        public class Oilyfatse
        {
            /// <summary>
            /// 膘油称重
            /// </summary>
            public int OilyfatId { get; set; }
            /// <summary>
            /// 仓库
            /// </summary>
            public string DepotTypeName { get; set; }

            /// <summary>
            /// 计划号
            /// </summary>
            public string OilyfatPlanNum { get; set; }

            /// <summary>
            /// 称重时间
            /// </summary>
            public DateTime OilyfatTime { get; set; }

            /// <summary>
            /// 商品代号
            /// </summary>
            public string UPCDataName { get; set; }

            /// <summary>
            /// 件数
            /// </summary>
            public string OilyfatNum { get; set; }
            /// <summary>
            /// 毛重
            /// </summary>
            public string OilyfatGrossWeight { get; set; }

            /// <summary>
            /// 皮重
            /// </summary>
            public string OilyfatTares { get; set; }

            /// <summary>
            /// 净重
            /// </summary>
            public string OilyfatWeight { get; set; }


            /// <summary>
            /// 备注
            /// </summary>
            public string OilyfatRemark { get; set; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (pageIndex != 1)
            {
                pageIndex = 1;
            }
            OilyfatShow_Load(sender, e);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (pageIndex > 1)
            {
                pageIndex--;
            }
            else
            {
                //弹框提示
                MessageBox.Show("已经第一页了");
            }
            OilyfatShow_Load(sender, e);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (pageIndex < pagecount)
            {
                pageIndex++;
            }
            else
            {
                //弹框提示
                MessageBox.Show("已经最后一页了");
            }
            OilyfatShow_Load(sender, e);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (pageIndex != pagecount)
            {
                pageIndex = pagecount;
            }
            OilyfatShow_Load(sender, e);
        }

        public record Oilyfatss(int OilyfatId);

        private async void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (MessageBox.Show("您确定要删除吗？", "此删除为逻辑删除", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
            {
                if (e.ColumnIndex == dataGridView1.Columns["删除"].Index)
                {
                    var wins = (int)e.RowIndex;
                    if (wins >= 0)
                    {
                        int OilyfatId = Convert.ToInt32(dataGridView1.Rows[wins].Cells["序号"].Value);

                        Oilyfatss oilyfatss = new(OilyfatId);

                        var items = await HttpClientHelper.RequestUrl<Oilyfatss, ApiResult<List<Oilyfatse>>>(URLCommon.Url1, "/WorkList01_leo/GetOilyfatDel", HttpClientHelper.MethodType.POST, oilyfatss);

                        if (items.Code == 1)
                        {
                            MessageBox.Show("删除成功");
                        }
                        else
                        {
                            MessageBox.Show("删除失败");
                        }


                    }
                }
            }
        }
    }
}
